uniapp中打开第三方应用
使用launchApplication方法打开第三方应用
以打开谷歌验证器为例
// #ifdef APP-PLUS
if (this.platform === 'ios') {
// ios接收action,action是应用的schema
plus.runtime.launchApplication({
action: `googleauthenticator://` // 谷歌验证器的schema
}, err => {
this.$u.toast(err)
});
} else {
// 安卓接收pname,pname是应用的包名
plus.runtime.launchApplication({
pname: 'com.google.android.apps.authenticator2' // 谷歌验证器的包名
}, err => {
this.$u.toast(err)
});
}
// #endif
如何寻找一个 App 的 URL Schemes
ios打开appStore,并定位到对应的应用
以谷歌验证器app为例
let appleId = 388497605 // 谷歌验证器的appid
// ios打开app store
plus.runtime.launchApplication({
action: `itms-apps://itunes.apple.com/app/id${appleId}?mt=8`
}, err => {
this.$u.toast(err)
});
如何查找ios应用的appid?
打开app store,进入应用详情,点击分享
![](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/2492b71a26b941328dbd5554c342f807~tplv-k3u1fbpfcp-zoom-in-crop-mark:1512:0:0:0.awebp)
拷贝链接,得到类似这样的链接:apps.apple.com/sg/app/mari…
其中:1293634699就是该应用的id
Android打开Google Play,并定位到应用详情
这里需要使用openURL方法,其第三个参数可以接收一个应用包名:使用该应用打开url
这里url设计,参考谷歌商店的文档:(需翻墙)链接到Google Play
// 通过谷歌商店打开谷歌验证器,id后面是应用的包名
const url = 'https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2'
plus.runtime.openURL(url, err => {
this.$u.toast(err)
}, "com.android.vending"); // "com.android.vending"是谷歌商店的包名
如何查找谷歌商店应用的包名?
打开谷歌商店官网(需翻墙)Google Play
![](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/cce6d19c868c48c78a731b4d56dbb502~tplv-k3u1fbpfcp-zoom-in-crop-mark:1512:0:0:0.awebp)
搜索,进入应用详情,此时网页的链接中就包含该应用的包名
![](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/c440c0a5c1b347cf84f2d55675f14605~tplv-k3u1fbpfcp-zoom-in-crop-mark:1512:0:0:0.awebp)
|